﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Xml;

namespace SaveRegistryXml
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cbRegType.Items.Add("HKEY_CLASSES_ROOT");
            cbRegType.Items.Add("HKEY_CURRENT_USER");
            cbRegType.Items.Add("HKEY_LOCAL_MACHINE");
            cbRegType.Items.Add("HKEY_USERS");
            cbRegType.Items.Add("HKEY_CURRENT_CONFIG");
            cbRegType.Text = "HKEY_LOCAL_MACHINE";
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            
                RegistryKey mainKey = ExtractRegisteryToXml.ExtractRegistery.getMainKeyByName(cbRegType.SelectedText);

                XmlDocument xDoc = new XmlDocument();

                xDoc.AppendChild(xDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes"));

                RegistryKey rKeySub = mainKey.OpenSubKey(txtReg.Text);

                xDoc.AppendChild(ExtractRegisteryToXml.ExtractRegistery.readRegisteryKey(rKeySub, xDoc));

                string fileName = Application.StartupPath + Guid.NewGuid().ToString() + ".xml";
                MessageBox.Show(fileName);
                xDoc.Save(fileName);

                wbShowXml.Navigate(fileName);


            
            
            

        }
    }
}
